package com.cz.video.website.controller;


import cn.hutool.core.util.ObjectUtil;
import com.cz.video.common.annotation.Log;
import com.cz.video.common.core.controller.BaseController;
import com.cz.video.common.core.domain.PageQuery;
import com.cz.video.common.core.domain.R;
import com.cz.video.common.core.page.TableDataInfo;
import com.cz.video.common.enums.BusinessType;
import com.cz.video.common.exception.ServiceException;
import com.cz.video.website.domain.bo.WebsiteLikeBo;
import com.cz.video.website.domain.vo.WebsiteLikeVo;
import com.cz.video.website.service.WebsiteLikeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 点赞信息 前端控制器
 * </p>
 *
 */
@Tag(name = "点赞管理")
@RequiredArgsConstructor
@RestController
@RequestMapping("/website/like")
public class WebsiteLikeController extends BaseController {

  private final WebsiteLikeService likeService;

  /**
   * 分页获取点赞信息
   *
   * @param likeBo 查询参数
   * @param pageQuery 分页参数
   *
   * @return 分页点赞信息
   */
  @Operation(summary = "分页获取点赞信息")
  @GetMapping("/list")
  public TableDataInfo<WebsiteLikeVo> list(WebsiteLikeBo likeBo, PageQuery pageQuery) {
    if (ObjectUtil.isNull(likeBo.getSourceId())&&ObjectUtil.isNull(likeBo.getUserId()))
        throw new ServiceException("查询点赞信息时没有源id或用户id参数");
//    if (LoginHelper.isWebsiteUser()){
//        likeBo.setUserId(LoginHelper.getWebsiteUserId());
//    }
    return likeService.page(likeBo, pageQuery);
  }



  /**
   * 删除点赞
   *
   * @param ids 点赞
   *
   * @return 影响行数
   */
  @Log(title = "删除点赞", businessType = BusinessType.DELETE)
  @Operation(summary = "删除点赞")
  @DeleteMapping("/{ids}")
  public R<Void> remove(@PathVariable("ids") Long[] ids) {
    return toAjax(likeService.deleteByUserIds(ids));
  }


}
